/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.vale.dao;

import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.vale.entity.State;

/**
 *
 * @author Gabriel Bran gbran.u@gmail.com
 */
@Stateless
public class StateDAO extends AbstractFacade<State, String> {

    @PersistenceContext(unitName = "ValeEsperarPU")
    private EntityManager entityManager;

    public StateDAO() {
        super(State.class);
    }

    @Override
    protected EntityManager getEntityManager() {
        return entityManager;
    }

    @Override
    public List<State> findAll() {
        Query query = entityManager.createQuery("SELECT c FROM State c ORDER BY c.statename", State.class);
        List<State> l = query.getResultList();
        return (l != null ? l : new ArrayList<State>());
    }
}
